package com.getpebble.android.common.model;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import com.getpebble.android.common.core.util.ObjectUtil;

public class PblDevice implements Parcelable {
    public static final Creator<PblDevice> CREATOR = new Creator<PblDevice>() {
        public PblDevice createFromParcel(Parcel source) {
            return new PblDevice(source);
        }

        public PblDevice[] newArray(int size) {
            throw new UnsupportedOperationException();
        }
    };
    private String mAddress;
    private String mName;
    private short mRssi;

    public PblDevice(String name, String address, short rssi) {
        this.mRssi = Short.MAX_VALUE;
        if (name == null) {
            throw new IllegalArgumentException("name null");
        } else if (address == null) {
            throw new IllegalArgumentException("address null");
        } else {
            this.mName = name;
            this.mAddress = address;
            this.mRssi = rssi;
        }
    }

    public PblDevice(String name, String address) {
        this(name, address, Short.MAX_VALUE);
    }

    public PblDevice(Parcel in) {
        this.mRssi = Short.MAX_VALUE;
        this.mName = in.readString();
        this.mAddress = in.readString();
    }

    public String getName() {
        return this.mName.toUpperCase();
    }

    public String getAddress() {
        return this.mAddress;
    }

    public short getRSSI() {
        return this.mRssi;
    }

    public int describeContents() {
        return 0;
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.mName);
        dest.writeString(this.mAddress);
    }

    public boolean equals(Object o) {
        if (o == null) {
            return false;
        }
        if (o == this) {
            return true;
        }
        if (o instanceof PblDevice) {
            return ObjectUtil.nullCheckEquals(((PblDevice) o).getAddress(), getAddress());
        }
        return false;
    }

    public int hashCode() {
        return this.mAddress.hashCode() + 355;
    }

    public String toString() {
        return getName();
    }
}
